//
//  FRTabBarViewController.m
//  Live
//
//  Created by 徐芙蓉 on 2017/7/25.
//  Copyright © 2017年 Afra. All rights reserved.
//

#import "FRTabBarViewController.h"
#import "FRTabBar.h"
#import "FRBaseNavViewController.h"
#import "FRLaunchViewController.h"

@interface FRTabBarViewController ()<FRTabBarDelegate>
@property (nonatomic, strong) FRTabBar *frTabbar;
@end

@implementation FRTabBarViewController

-(FRTabBar *)frTabbar
{
    if (!_frTabbar) {
        _frTabbar = [[FRTabBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 49)];
        _frTabbar.delegate = self;
    }
    return _frTabbar;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //加载控制器
    [self configViewControllers];
    //加载tabbar
    [self.tabBar addSubview:self.frTabbar];
    
    //解决tabbar的阴影线
    [[UITabBar appearance] setShadowImage:[UIImage new]];
    [[UITabBar appearance] setBackgroundImage:[UIImage new]];
    
}

-(void)configViewControllers
{
    NSMutableArray *array = [NSMutableArray arrayWithArray:@[@"FRMainViewController",@"FRMeViewController"]];
    for (NSInteger i = 0; i < array.count; i++) {
        UIViewController *viewController = [[NSClassFromString(array[i]) alloc]init];
        FRBaseNavViewController *nav = [[FRBaseNavViewController alloc]initWithRootViewController:viewController];
        [array replaceObjectAtIndex:i withObject:nav];
//        [self addChildViewController:nav];
    }
    self.viewControllers = array;
    }

#pragma mark -- FRTabBarDelegate
-(void)tabbar:(FRTabBar *)tabbar clickButton:(FRItemType)idx
{
    if (idx != FRItemTypeLaunch) {
        self.selectedIndex = idx - FRItemTypeLive;
        return;
    }
    
    FRLaunchViewController *launchVC = [[FRLaunchViewController alloc]init];
    [self presentViewController:launchVC animated:YES completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
